import { _decorator, Component, Node, RichText } from 'cc';
import { UIHeader } from '../common/UIHeader';
import { EventManager } from '../event/EventManager';
import { UIManager } from '../common/UIManager';
import { PrefabEnum } from '../common/PrefabEnum';
import { Report } from '../entity/Report';
import { OperationItem } from '../entity/OperationItem';
import { OperationType } from '../entity/OperationType';
import { ColorEnum } from '../entity/ColorEnum';
const { ccclass, property } = _decorator;

@ccclass('ReportFight')
export class ReportFight extends Component {

    @property(UIHeader)
    uiHeader: UIHeader
    @property(RichText)
    richText: RichText

    start() {
        this.uiHeader.setData('英雄对决')
        EventManager.instance.on('英雄对决close', this.onClose, this)
    }

    setData(report: Report) {
        console.log(report)
        let rs = JSON.parse(report.content);
        let names = JSON.parse(report.rParam);
        console.log(names)
        let fightStr = ''
        for (let item of rs) {
            let op = new OperationItem(item)
            op.translate(names)
            console.log(item.params.desc)
            fightStr += item.params.desc + '\n'
            switch (op.type) {
                case OperationType.Start:
                    // this.setStart(op)
                    break
                case OperationType.Enter:
                    // this.setEnter(op)
                    break
                default:
                // this.operation.push(op);
            }
        }

        this.richText.string =`<color=${ColorEnum.GrayYellow}>${fightStr}</color>` 
    }


    onClose() {
        UIManager.instance.closeUI(PrefabEnum.ReportFight)
    }

}


